import 'dart:collection';

import 'package:auto_route/auto_route.dart';
import 'package:dio/dio.dart';
import 'package:tender_flutter/constant/api_path.dart';
import 'package:tender_flutter/constant/app_config.dart';
import 'package:tender_flutter/http/api_response.dart';
import 'package:tender_flutter/http/http_utils.dart';

class ApiTrack {
  /// 添加追踪
  /// businessId 企业id
  static Future addTrack<T>(
      {@required String companyKey, @required String companyName}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["companyKey"] = companyKey;
      params["companyName"] = companyName;
      final response = await HttpUtils.get(ApiPath.addTrack, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 获取添加的追踪列表
  static Future getTrackList<T>(
      {int page = AppConfig.page, int pageCount = AppConfig.pageCount}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["page"] = page;
      params["size"] = pageCount;
      final response = await HttpUtils.get(ApiPath.trackList, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 获取追踪企业的标讯信息
  static Future getTrackCompanyTenderList<T>(
      {String companyName,
      int page = AppConfig.page,
      int pageCount = AppConfig.pageCount}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["companyName"] = companyName;
      params["page"] = page;
      params["size"] = pageCount;
      final response =
          await HttpUtils.get(ApiPath.trackCompanyTenderList, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 模糊查询需要追踪的企业列表
  static Future getCompanyTrackList<T>({String title}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["title"] = title;
      final response =
          await HttpUtils.get(ApiPath.trackCompanyList, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  // /// 企业动态
  // static Future getCompanyDynamic<T>(
  //     {String companyKey,
  //     int page = AppConfig.page,
  //     int pageCount = AppConfig.pageCount}) async {
  //   try {
  //     Map<String, dynamic> params = HashMap();
  //     params["companyKey"] = companyKey;
  //     params["page"] = page;
  //     params["size"] = pageCount;
  //     final response =
  //         await HttpUtils.get(ApiPath.companyDynamic, params: params);
  //     return ApiResponse<T>.completed(response);
  //   } on DioError catch (e) {
  //     return ApiResponse.error(e.error);
  //   }
  // }
}
